<template>
    <div>
        <a-modal v-model="show" title="编辑" @ok="handleOk" @cancel="show = false">
            <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 19 }">
                <a-form-item label="风险等级">
                    <a-input v-model="form.dangerLevel" />
                </a-form-item>
                <a-form-item label="风险描述">
                    <a-input v-model="form.dangerTitle" />
                </a-form-item>
                <a-form-item label="隐患分类">
                    <a-input v-model="form.dangerType" />
                </a-form-item>
                <a-form-item label="上报人">
                    <a-select v-model="form.reportUserId" placeholder="选择上报人" show-search>
                        <a-select-option :value="item.userId" v-for="(item, index) in userAllList" :key="index">
                            {{ item.userName }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-item label="复审人">
                    <a-select v-model="form.recheckUserId" placeholder="选择复审人" show-search>
                        <a-select-option :value="item.userId" v-for="(item, index) in userAllList" :key="index">
                            {{ item.userName }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
            </a-form>
        </a-modal>
    </div>
</template>
<script>
    import { message } from 'ant-design-vue';
    import { postHiddenUpdate } from "@/services"
    export default {
        props: {
            // 全部用户:列表
            userAllList: {
                default: () => { },
                type: Array,
            },
        },
        data() {
            return {
                // 是否显示弹框
                show: false,
                // 表单
                form: {
                    dangerRecordId: '',
                    dangerLevel: '',
                    dangerTitle: '',
                    dangerType: '',
                    recheckUserId: '',
                    reportUserId: '',
                },
            }
        },
        methods: {
            /**
             * 打开弹框
             */
            open(data) {
                this.show = true // 打开弹框
                this.form = this.$options.data().form // 初始化
                if (data?.id || data?.dangerRecordId) {
                    this.form = data
                    this.form.dangerRecordId = data.id
                }
            },
            /**
             * 确认提交
             */
            async handleOk() {
                let { form } = this
                if (form.dangerRecordId == '') {
                    return message.warning('未获取到Id')
                }
                let res = await postHiddenUpdate(this.form)
                if (res.code == 0) {
                    message.success('修改成功')
                } else {
                    return message.warning(res?.msg)
                }
                this.show = false
                this.$emit('ok', 1);
            }
        },
    }
</script>